package com.jhs.kjs.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.jhs.kjs.dto.CarGroupDTO;
import com.jhs.kjs.dto.CarTypeDTO;
import com.jhs.kjs.dto.DeptDTO;
import com.jhs.kjs.dto.combine.CarCusInfoDetail;
import com.jhs.kjs.service.IEnvCarInfoService;
import com.jhs.kjs.service.dao.IEnvCarInfoMapper;
public class EnvCarInfoServiceImpl implements IEnvCarInfoService{

	private IEnvCarInfoMapper mapper;

	public void setMapper(IEnvCarInfoMapper mapper) {
		this.mapper = mapper;
	}

	@Override
	public List<CarCusInfoDetail> getTotalCarList(
			CarCusInfoDetail CarDTO) {
		return mapper.getTotalCarList(CarDTO);
	}

	@Override
	public List<CarGroupDTO> getCarGroupDTO(Long customerCode) {
		return mapper.getCarGroupDTO(customerCode);
	}

	@Override
	public List<DeptDTO> getDeptList(Long customerCode) {
		return mapper.getDeptList(customerCode);
	}

	@Override
	public List<CarTypeDTO> getCarTypeList() {
		return mapper.getCarTypeList();
	}

	@Override
	public void updateInfo(CarCusInfoDetail info) {
		mapper.updateInfo(info);
		mapper.updateInfo_CARDRIVER(info);
//		mapper.updateInfo_BAGGAGE(info);
	}

	@Override
//	@Transactional()
	public String deleteGroupItem(List<CarGroupDTO> carGroupList) {
		String retMsg="성공";
		Map<String, Object> param = new HashMap<String, Object>();
		List<Long> groupCode = new ArrayList<Long>();
		for(CarGroupDTO c : carGroupList){
			groupCode.add(c.getCarGroupCode());
		}
		param.put("customerCode", carGroupList.get(0).getCommon_customerCode());
		param.put("groupCode", groupCode);
		
		Integer cnt = mapper.getCountIfDeleteCarGroupCode(param);
		System.out.println("리턴된 결과 = "+cnt);
		if(cnt<1){
			return "그룹은 최소 1개 이상 남아야 합니다.";
		}
		
		mapper.updateCustomerUser(param);
		mapper.deleteGroupItem(param);
		
		return retMsg;
	}

	@Override
	public void addGroupItem(Map<String, Object> param) {
		mapper.addGroupItem(param);
	}
	
}
